package com.example.footballsystem.controller;

import com.example.footballsystem.entity.News;
import com.example.footballsystem.service.NewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/News")
@CrossOrigin(origins = "*")
public class NewsController {
    @Autowired
    NewsService newsService;
    @PostMapping("/addNew")
    public ResponseEntity<Boolean> addNew(@RequestBody News news){
        //log.info(news.toString());
        return ResponseEntity.ok().body(newsService.addNew(news));
    }
    @PostMapping("/getAllNews")
    public ResponseEntity<List<News>> getAllNews(){
        log.info(newsService.getAllNews().toString());
        return ResponseEntity.ok().body(newsService.getAllNews());
    }
    @PostMapping("/deleteNews")
    public ResponseEntity<Boolean> deleteNews(@RequestBody List<News> news){
        for(int i = 0; i<news.size(); i++){
            newsService.deleteNew(news.get(i));
        }
        return ResponseEntity.ok().body(true);
    }
    @GetMapping("/searchNews")
    public ResponseEntity<List<News>> searchNews(String info){
        return ResponseEntity.ok().body(newsService.searchNews(info));
    }
}
